package com.bing.habit.controller.user;

import com.bing.habit.entity.TomatoRecord;
import com.bing.habit.model.result.Result;
import com.bing.habit.model.result.ResultFactory;
import com.bing.habit.service.TomatoRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 番茄记录
 */
@RestController
@RequestMapping("/tomato")
public class TomatoController {
    @Autowired
    TomatoRecordService tomatoRecordService;

    @PostMapping
    public Result add(@RequestBody TomatoRecord tomatoRecord){
        tomatoRecord.setFinishTime(new Date());
        tomatoRecordService.add(tomatoRecord);
        return ResultFactory.buildSuccessResult("添加成功");
    }

    /**
     * 累计番茄
     */
    @GetMapping("/list/{userId}")
    public Result list(@PathVariable("userId") int uid){
        List<TomatoRecord> tomatoRecords =  tomatoRecordService.list(uid);
        return ResultFactory.buildSuccessResult(tomatoRecords);
    }

    /**
     * 列出今日番茄  -- 根据番茄累加得出今日时长
     */
    @GetMapping("/listToday/{userId}")
    public Result listToday(@PathVariable("userId") int uid){
        List<TomatoRecord> tomatoRecords =  tomatoRecordService.listToday(uid);
        return ResultFactory.buildSuccessResult(tomatoRecords);
    }

    /**
     * 列出本周  -- 根据累加得出本周时长
     */
    @GetMapping("/listWeek/{userId}")
    public Result listWeek(@PathVariable("userId") int uid){
        List<TomatoRecord> tomatoRecords =  tomatoRecordService.listWeek(uid);
        return ResultFactory.buildSuccessResult(tomatoRecords);
    }
}
